define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'crm.contract/index',
        add_url: 'crm.contract/add',
        edit_url: 'crm.contract/edit',
        delete_url: 'crm.contract/delete',
        export_url: 'crm.contract/export',
        modify_url: 'crm.contract/modify',
    },util = layui.util;

    var Controller = {

        index: function () {
            ea.table.render({
                toolbar: ['refresh','delete'],
                init: init,limit:CONFIG.ADMINPAGESIZE,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID'},
                    {field: 'khname', title: '客户名称',search:true},
                    {field: 'khphone', title: '客户联系电话',search:true},
                    {field: 'pr_user', title: '跟进者',search:true},
                    {field: 'content', title: '合同描述',search:true},
                    {field: 'create_time', title: '上传时间',sort:true,"search":"range","templet":ea.table.date},
                    {width: 100, title: '操作', templet: ea.table.tool,operat:['delete']},
                ]],
                done: function(res, curr, count){
                       if(count===undefined && res.msg && res.url){
                           ea.msg.tips(res.msg,1,function (){
                               window.top.location.href=res.url;
                           })
                       }
                },where: {scope: 1}
            });

            ea.listen();
        },dialogue:function (){
            ea.listen('',
                function (res) {
                    ea.msg.success(res.msg, function () {
                        $('#content').val('');
                        $('.layui-timeline').append("<li class=\"layui-timeline-item\">\n" +
                            "                        <i class=\"layui-icon layui-timeline-axis\"></i>\n" +
                            "                        <div class=\"layui-timeline-content layui-text\">\n" +
                            "                            <h3 class=\"layui-timeline-title\" style=\"color: rosybrown;font-size: 15px\">\n" +
                            "\n" +
                            "                                "+res.data.create_time+'（'+res.data.contract_type+'）'+"</h3>\n" +
                            "                                <div>\n" +
                            "                                <div style=\"display: inline-block\">\n" +
                            "                                    <img src=\""+CONFIG.ADMIN.avatar+"\" alt=\"\" style=\"width: 30px;height: 30px;border-radius: 50%\">\n" +
                            "                                    <strong>"+CONFIG.ADMIN.username+"：</strong>\n" +
                            "                                </div>\n" +
                            "                                "+ res.data.content+"\n" +

                            "                                </div>\n" +
                            "                        </div>\n" +
                            "                    </li>");
                    })
                }, function (res) {
                    ea.msg.error(res.msg, function () {

                    });
                });
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});